<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>书籍典藏</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#btnExport").click(function(){
                parent.$.jBox.confirm("确认要导出馆藏数据吗？","系统提示",function(v,h,f){
                    if(v=="ok"){
                        $("#searchForm").attr("action","${ctx}/book/store/export").submit();
                        $("#searchForm").attr("action","${ctx}/book/store/");
                    }
                },{buttonsFocus:1});
                top.$('.jbox-body .jbox-icon').css('top','55px');
            });
        });
        function page(n,s){
            $("#pageNo").val(n);
            $("#pageSize").val(s);
            $("#searchForm").submit();
            return false;
        }
        function btnClear() {
            $("#searchForm").find("input[type='text']").each(function () {
                $(this).val("");
            });
            $("#s2id_store").children("a").find(".select2-chosen").html("全部");
            $("#store").val("");
        }

        function deleteBkStore(id) {
            if(confirm("确定要删除典藏信息？")){
                deleteBookStoreAjax(id);
            }
        }
        function deleteBookStoreAjax(storeId) {
            $.ajax({
                type: "POST",
                url: "${ctx}/book/store/deleteByStoreId",
                data: {storeId: storeId},
                dataType: "json",
                success: function (data) {
                    if (data.code == "0001") {
                        top.$.jBox.info(data.msg, '提示', {
                            closed: function () {
                                window.location.href = "${ctx}/book/store/list";
                            }
                        });
                        top.$('.jbox-body .jbox-icon').css('top', '55px');

                    } else {
                        alertx("删除书籍典藏信息失败");
                    }
                },error:function(){
                    top.$.jBox.info("删除书籍典藏信息失败", '提示', {
                        closed: function () {
                            window.location.href = "${ctx}/book/store/list";
                        }
                    });
                    top.$('.jbox-body .jbox-icon').css('top', '55px');
                }
            });
        }

        function changeStore(storeId, placeid) {
            parent.$.jBox.open("iframe:${ctx}/book/store/changestore?storeId=" + storeId + "&placeid=" + placeid, "书库调拨",600,350,{
                buttons: {},
                closed: function () {
                    if(window.parent.refresh){
                        window.location.href = "${ctx}/book/store/list";
                    }
                }
            });
        }
        function checkStore(obj){
            if($(obj).prop("checked")){
               $("#store_list").find("input[name='storeIds']").each(function(){
                   $(this).attr("checked", true);
               });
            }else{
                $("#store_list").find("input[name='storeIds']").each(function(){
                    $(this).attr("checked", false);
                });
            }
        }
        function getSelectStoreIds(){
            var storeIds = "";
            $("#store_list").find("input[name='storeIds']").each(function () {
                if ($(this).prop("checked")) {
                    storeIds += $(this).val()+",";
                }
            });
            return storeIds;
        }
        function deleSelectStore(){
            var storeIds = getSelectStoreIds();
            if (storeIds.length < 2) {
                alertx("请先选择要删除的典藏数据！");
            } else {
                if(confirm("确定要删除典藏信息？")){
                    $.post("${ctx}/book/store/deleteStoreByStoreIds", {storeIds: storeIds}, function (result) {
                        if (result.code == '0001') {
                            alertx("删除典藏数据成功！",function(){$("#btnSubmit").click();});
                        }
                    });
                }
            }
        }
        function printMark(flag){
            var storeIds = getSelectStoreIds();
            if (storeIds.length < 2) {
                alertx("请先选择要打印的典藏数据！");
            } else {
                // 补打条码
                if (flag == 0) {
                    var banIds = "";
                    $("#store_list").find("input[name='storeIds']").each(function () {
                        if ($(this).prop("checked")) {
                            banIds += $(this).attr('title')+",";
                        }
                    });
                    window.location.href = "${ctx}/book/purchase/printsn?banIds=" + banIds;
                }
                // 补打书标
                else if (flag == 1) {
                    window.location.href = "${ctx}/book/purchase/printPlace?storeIds=" + storeIds;
                }
            }
        }
    </script>
    <style type="text/css">
        .s_div {
            float: left;
        }
    </style>
</head>
<body>
<%--<ul class="nav nav-tabs">--%>
    <%--<li class="active">--%>
        <%--<a href="${ctx}/book/store/list">典藏列表</a>--%>
    <%--</li>--%>
    <%--&lt;%&ndash;<li>&ndash;%&gt;--%>
        <%--&lt;%&ndash;<a href="${ctx}/book/store/form?isEdit=true&isNew=true">图书典藏（新增）</a>&ndash;%&gt;--%>
    <%--&lt;%&ndash;</li>&ndash;%&gt;--%>
<%--</ul>--%>
<%--<br/>--%>
<form:form id="searchForm" modelAttribute="bkBookstore" action="${ctx}/book/store/" method="post"
           class="breadcrumb form-search">
    <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
    <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
    <ul class="ul-form">
        <li>
            <label>条码号：</label>
            <form:input path="banid" htmlEscape="false" maxlength="18" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>ISBN：</label>
            <form:input path="isbn" htmlEscape="false" maxlength="18" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>书名：</label>
            <form:input path="bookname" htmlEscape="false" maxlength="18" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>著者：</label>
            <form:input path="author" htmlEscape="false" maxlength="30" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>分类号：</label>
            <form:input path="classcode" htmlEscape="false" maxlength="30" class="input-small"/>&nbsp;
        </li>
        <%--<div class="s_div">--%>
            <%--<label>索书号：</label>--%>
            <%--<form:input path="place" htmlEscape="false" maxlength="18" class="input-small"/>&nbsp;--%>
        <%--</div>--%>
        <li>
            <label>索书号：</label>
            <form:input path="place" htmlEscape="false" maxlength="18" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>丛编：</label>
            <form:input path="books" htmlEscape="false" maxlength="30" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>出版社：</label>
            <form:input path="publisher" htmlEscape="false" maxlength="30" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>版次：</label>
            <form:input path="version" htmlEscape="false" maxlength="30" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>出版日期：</label>
            <form:input path="pubdate" htmlEscape="false" maxlength="30" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>验收批次：</label>
            <form:input path="batch" htmlEscape="false" maxlength="30" class="input-small"/>&nbsp;
        </li>
        <li>
            <label>验收时间：</label>
            <input id="beginDate"  name="beginDate"  type="text" readonly="readonly" maxlength="20" class="input-medium Wdate" style="width:163px;"
                   value="<fmt:formatDate value="${beginDate}" pattern="yyyy-MM-dd"/>"
                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});"/>
            　--　
            <input id="endDate" name="endDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate" style="width:163px;"
                   value="<fmt:formatDate value="${endDate}" pattern="yyyy-MM-dd"/>"
                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});"/>
        </li>
        <li>
            <label class="field">选择书库：</label>
            <form:select path="store" items="${fns:getAllStoreList(true)}" itemLabel="gcdName"
                         itemValue="placeid" cssStyle="width: 180px;" class="input-medium"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </li>
        <li>
            <label class="field">选择书架：</label>
            <form:select path="shelfid" items="${fns:getAllShelfList(true)}" itemLabel="name"
                         itemValue="id" cssStyle="width: 180px;" class="input-medium"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </li>
        <li>
            <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="javascript:void(0)" onclick="btnClear()" class="btn">清空条件</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a id="btnExport" href="javascript:void(0)" class="btn">导出Excel</a>
        </li>
    </ul>
</form:form>
<sys:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th><input name="check" type="checkbox" onclick="checkStore(this)">序号</th>
        <th>条形码</th>
        <th>ISBN</th>
        <th>索书号</th>
        <th>题名</th>
        <th>副题名</th>
        <th>丛编</th>
        <th>价格</th>
        <th>分册号</th>
        <th>著者</th>
        <th>出版社</th>
        <th>批次</th>
        <th>馆藏地</th>
        <th>书架号</th>
        <%--<th>在馆</th>--%>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="store_list">
    <c:forEach items="${page.list}" var="store" varStatus="status">
        <tr>
            <td><input name="storeIds" value="${store.id}" title="${store.banid}" type="checkbox">${status.count}</td>
            <td>${store.banid}</td>
            <td>${store.isbn}</td>
            <td>${store.classcode}/${store.place}</td>
            <td><a href="${ctx}/book/store/?repage&bookname=${store.bookname}">${store.bookname}</a></td>
            <td>${store.othername}</td>
            <td><a href="${ctx}/book/store/?repage&books=${store.books}">${store.books}</a></td>
            <td>${store.price}</td>
            <td>${store.booksnum}</td>
            <td><a href="${ctx}/book/store/?repage&author=${store.author}">${store.author}</a></td>
            <td><a href="${ctx}/book/store/?repage&publisher=${store.publisher}">${store.publisher}</a></td>
            <td>${store.batch}</td>
            <td>
                <a href="${ctx}/book/store/?repage&store=${store.store}">
                    ${store.storeName}
                </a>
            </td>
            <td>${store.shelf.name}</td>
            <%--<td>${store.leftCount>=1?'在馆':'不在馆'}</td>--%>
            <td>
                <shiro:hasPermission name="book:store:save">
                    <a href="${ctx}/book/store/form?bkId=${store.bkId}&id=${store.id}&isEdit=true">修改</a>
                </shiro:hasPermission>
                <shiro:hasPermission name="book:store:delete">
                    <a href="javascript:void(0);" onclick="deleteBkStore('${store.id}')">删除</a>
                </shiro:hasPermission>
                <shiro:hasPermission name="book:store:save">
                    <a href="javascript:changeStore('${store.id}', '${store.store}')">调拨</a>
                </shiro:hasPermission>
                <a href="${ctx}/book/store/form?bkId=${store.bkId}&id=${store.id}&isEdit=false">查看</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div>
    <div style="float: left">
        <a class="btn" href="javascript:void(0);" onclick="deleSelectStore();">删除</a>
        <a class="btn" href="javascript:void(0);" onclick="printMark(0);">补打条码</a>
        <a class="btn" href="javascript:void(0);" onclick="printMark(1);">补打书标</a>
    </div>
    <div class="pagination" style="margin-left: 240px">${page}</div>
</div>
</body>
</html>